
<template>
  <view class="tenantlease">
    <!-- <hunk-head name="马上安家"></hunk-head> -->
    <div class="banner">
      <img :src="banner" alt="" srcset="">
    </div>
    <scroll-view
      class="prv-container"
      scroll-y="true"
      @scrolltolower="_onLoadmore"
      :refresher-enabled="refresherEnabled"
      :refresher-triggered="triggered"
      @refresherrefresh="onRefresh"
      @refresherrestore="triggered = false"
      @refresherabort="triggered = false"
    >
    <div class="order-list">
      <div class="list-item" v-for="(item, index) in list" :key="index" @click="detail(item)" >
        <div class="leftImg">
          <img :src="item.defaultimg" alt="" srcset="">
        </div>
        <div class="rightText">
          <div class="text-top">
            {{item.address}}
          </div>
          <div class="time">
            <span>开始时间：</span>
            {{item.starttime}}
          </div>
          <div class="time">
            <span>结束时间：</span>
            {{item.endtime}}
          </div>
          <div class="btn">
            <div class="status">
              <img v-if="item.state!=4" :src="imgs[item.state-1]" alt="" srcset="">
              <div v-else> 强制退租</div>
            </div>
            
          </div>
        </div>
      </div>
    </div>
    <div v-if="isnone < 1" class="none">
      <img v-if="baseUrl" :src="baseUrl+'imgs/imgs/none.png'" alt="">
    </div>
    </scroll-view>
  </view>
</template>

<script>
const imgUrl = `${process.env.VUE_APP_BASE_IMG_URL}`
const banner = imgUrl+'order/banner.png'
const over = imgUrl+'order/over.png'
const overed = imgUrl+'order/overed.png'
const zuing = imgUrl+'order/zuing.png'
import { getContractList } from '@/apis/tenant/leases'
export default {
  data() {
    return {
      refresherEnabled: true,
      triggered:false,
      banner,
      imgs:[
        zuing,
        over,
        overed
      ],
      list: [],
      limit: 10,
      offset: 0
    }
  },
  created(){
    this.offset = 1
    this.getContractList()
  },
  computed: {
    userid(){
      return this.$store.state.baseStore.userInfo.userid
    },
    isnone(){
      if(this.list){
        return this.list.length
       }else{
         return false
       }
    },
    baseUrl() {
      return process.env.VUE_APP_BASE_IMG_URL;
    }
  },
  methods: {
    detail(item){
      let querry = item
      querry.jumpAdd2 = 'zuke'
      this.$jump({ path: '/pages/tenant/lease/detaillease?query=' + JSON.stringify(item) })
    },
    onRefresh(){
      this.offset = 1
    this.getContractList()
      this.triggered = 'restore'
      setTimeout(() => {
        this.triggered = false
      }, 1000)
    },
    getContractList(){
      let data = {
        limit: this.limit+"",
        offset: this.offset+"",
        userid: this.userid
      }
      getContractList(data).then((res)=>{
        if(res.code == 200){
          if (this.offset === 1) {
            this.list = res.data
          }else if(this.list.length >= res.total){
            return
          } else {
            this.list = this.list.concat(res.data)
          }
        }else{
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    _onLoadmore(){
      ++this.offset
      this.getContractList()
      console.log('_onLoadmore')
    }
  }
}
</script>

<style lang="scss" scoped>
.tenantlease{
  // flex: 1;
  @include num();
  // min-height: calc(100vh - 50px);
  display: flex;
  flex-direction: column;
  .banner{
    width: 375px;
    height: 120px;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .prv-container{
    flex: 1;
    overflow-y: auto;
  }
  .none{
    width: 100vw;
    margin-top: 50px;
    // background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    img{
      width: 190px;
      height: 195px;
    }
  }
  .order-list{
    background: #fff;
    .list-item{
      box-sizing: border-box;
      padding: 15px;
      border-bottom: 2px solid #EFEFEF;
      display: flex;
      flex-direction: row;
    }
    .leftImg{
      width: 110px;
      height: 115px;
      border-radius: 4px;
      margin-right: 15px;
      img{
        width: 100%;
        height: 100%;
        border-radius: 4px;
      }
    }
    .rightText{
      
      .text-top{
        // height: 44px;
        font-size: 16px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 22px;
      }
      .time{
        margin-top: 4px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #4A4A4A;
        line-height: 20px;
        span{
          color: #9B9B9B;
        }
      }
      .btn{
        margin-top: 4px;
        display: flex;
        justify-content: space-between;
        .status{
          width: 62px;
          height: 20px;
          border-radius: 4px;
          img{
            width: 100%;
            height: 100%;
          }
          div{
            width: 100%;

            padding: 0 5px;
            height: 24px;
            box-sizing: border-box;
            // background: #EF1E13;
            background: rgba($color: #EF1E13, $alpha: 0.2);
            border-radius: 4px;
            font-size: 13px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #EF1E13;
            line-height: 24px;
            text-align: center;
          }
        }
        .tuizu{
          padding: 0 14px;
          height: 24px;
          background: #FF6B75;
          border-radius: 12px;
          font-size: 13px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #FFFFFF;
          line-height: 24px;
          text-align: center;
        }
      }
    }
  }
  .tips{
    width: 335px;
    height: 304px;
    background: #FFFFFF;
  }
  .close{
    position: absolute;
    top: 22px;
    right: 15px;
    width: 18px;
    height: 18px;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .tips-top{
    height: 60px;
    font-size: 18px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #4A4A4A;
    line-height: 60px;
    text-align: center;
  }
  .tishi{
    height: 37px;
    background: #FF6B75;
    font-size: 13px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FFFFFF;
    line-height: 37px;
    padding-left: 18px;
    display: flex;
    align-items: center;
    img{
      width: 16px;
      height: 16px;
      margin-right: 13px;
    }
  }
 .tips-text{
    box-sizing: border-box;
    padding-left: 15px;
    padding-top: 10px;
    .text-item{
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #9B9B9B;
      line-height: 20px;
      display: flex;
      margin: 5px 0;
      .left{
        margin-right: 12px;
      }
      .right{
        font-size: 14px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #4A4A4A;
        line-height: 20px;
      }
      .red{
        color: #FF6B75;
      }
    }
  }
  .tips-btn{
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-top: 15px;
      button{
        width: 305px;
        height: 45px;
        background: #CCCCCC;
        border-radius: 100px;
        font-size: 16px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #FFFFFF;
        line-height: 45px;
      }
      button::after{
        border: 0;
      }
    }
}


</style>
